﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Course.Entity;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.User.Entity;
using System.Collections.Generic;
using PowerCreator.LMS.Common.Utils;
using PowerCreator.LMS.Web.Paper;
using PowerCreator.LMS.Paper.Entiry;
using PowerCreator.LMS.Web.Config;
using PowerCreator.LMS.Web.Project;
using PowerCreator.LMS.Project.Entity;


public partial class Theme_3_OpenCourseWareCommentNew :PowerCreator.LMS.Web.Base.BasePage
{
    protected string fileUrl = string.Empty;
    protected string url = string.Empty;
    protected string ResourceID = string.Empty;
    protected string _Position = "0";

    protected string isUpdateCourse = "1";  //0不更新课件信息,1更新课件信息

    const string _openhistoryurl = "/web/Project/OpenHistory.aspx?ProjectID={0}&ProjectClassID={1}&ProjectClassUserID={2}&ProjectResourceID={3}&CourseResourceID={4}&ResourceID={5}&ProjectResourceResourceStartTime={6}";

    const  string   SEARCH_GETSUMSCORE = "select Sum(SkillTypeScore) as SumScore from TSkillType";

    const string IMG_OK = "<img src=\"images/x1.jpg\" width=\"16\" height=\"12\" />";
    const string IMG_NO = "<img src=\"images/x2.jpg\" width=\"16\" height=\"12\" />";

    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected string AddCommentUrl = "OpenCourseWareCommentNew.aspx?ProjectID={0}&ClassID={1}&UserID={2}&ProjectResourceID={3}&CourseResourceID={4}&ResourceID={5}&Position={6}&CourseID={7}";

    PowerCreator.LMS.Web.Comment.Comment opComment = new PowerCreator.LMS.Web.Comment.Comment();
    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    PowerCreator.LMS.Web.Course.Resource opResource = new PowerCreator.LMS.Web.Course.Resource();
    PowerCreator.LMS.ViewQuery.ViewQuery objViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    PowerCreator.LMS.Web.Grade.GradeManager objGradeManager = new PowerCreator.LMS.Web.Grade.GradeManager();
    PowerCreator.LMS.Web.Course.VirtualDirectory opVirtual = new VirtualDirectory();
    protected string _ResourceID = "0";
    ManagerPaper opPaper = new ManagerPaper();
    private PowerCreator.LMS.Web.DL.User.LoginEntity login = new PowerCreator.LMS.Web.DL.User.LoginEntity();
    private string Loginurl = "UserLogin.aspx";


    //protected string _userid = "0";

    protected void Page_Load(object sender, EventArgs e)
    {
        Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        CheckUser();
        if (!IsPostBack)
        {
            this.Title = config.GetLanagerValueByKey("theme_Comment_TitleInfo", PowerCreator.LMS.Language.LanagetItemType.Page);
            string projectid = Request.QueryString["ProjectID"].ToString();
            ViewState["ProjectID"] = projectid;
            string classid = Request.QueryString["ClassID"].ToString();
            ViewState["ClassID"] = classid;
            string userid = Request.QueryString["UserID"].ToString();
            ViewState["UserID"] = userid;
            string projectresourceid = Request.QueryString["ProjectResourceID"].ToString();
            ViewState["ProjectResourceID"] = projectresourceid;
            string courseresourceid = Request.QueryString["CoursResourceID"].ToString();
            ViewState["CoursResourceID"] = courseresourceid;
            string courseid = Request.QueryString["CourseID"].ToString();
            ViewState["CourseID"] = courseid;
            string resourceid = Request.QueryString["ResourceID"].ToString();
            ResourceID = resourceid;
            ViewState["ResourceID"] = resourceid;
            _ResourceID = resourceid;
            _Position = Request.QueryString["Position"].ToString();

             BinderUserLogin();
             btn_out.Text = config.GetLanagerValueByKey("SignOut", PowerCreator.LMS.Language.LanagetItemType.WebTitle);

            AddCommentUrl = string.Format(AddCommentUrl, projectid, classid, userid, projectresourceid, courseresourceid, resourceid, _Position, ViewState["CourseID"]);
            //初始化更新数据的URL
            // url = string.Format(URL_UPDATE_HISTORY, rid, prid, crid, courseid, projectresourceid, Base64.Encode(urid), Base64.Encode(DateTime.Now.ToString()));

            BinderPG();
            //_userid = GetUserID();
            SetOpenHistoryUrl();
            if(ViewState["CourseID"].ToString()=="")
                BinderOtherStowResource();
            else if (int.Parse(ViewState["CourseID"].ToString()) > 0)
                BinderCourseResource(ViewState["CourseID"].ToString());
            else
                BinderOtherStowResource();
        }
        if (Request.QueryString["TimePosition"] != null)
        {
            ViewState["TimePosition"] = Request.QueryString["TimePosition"].ToString();
        }

    }


    private void CheckUser()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            Script.RedirectURL(Loginurl);
        }

        login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
        if (login == null)
        {
            Script.RedirectURL(Loginurl);
        }

    }


    protected void lnkbtn_EN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "1";
    }
    protected void lnkbtn_CN_Click(object sender, EventArgs e)
    {
        Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_LANGEID] = "0";
    }
    protected void BinderUserLogin()
    {
        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
        {
            lal_UserLogin.Text = "<a  href=\"UserLogin.aspx\">" + config.GetLanagerValueByKey("SysManagerLogin", PowerCreator.LMS.Language.LanagetItemType.Page) + "</a> |  <a  href=\"Register.aspx\">" + config.GetLanagerValueByKey("SysManagerRegistor", PowerCreator.LMS.Language.LanagetItemType.Page) + "</a>";
            btn_out.Visible = false;
        }
        else
        {
            PowerCreator.LMS.Web.DL.User.LoginEntity login = (PowerCreator.LMS.Web.DL.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
            lal_UserLogin.Text = login.AccountInfo.RealName.Trim() + "," + config.GetLanagerValueByKey("Login_msg_code5", PowerCreator.LMS.Language.LanagetItemType.Page) + "！| ";
            btn_out.Visible = true;
        }
    }
    protected void btn_out_Click(object sender, EventArgs e)
    {
        //PowerCreator.LMS.Web.User.User opUser = new PowerCreator.LMS.Web.User.User();
        //opUser.UpdateOnlineUserByUserID(GetLoginEntity.UserID);
        Session.Abandon();
        PowerCreator.LMS.Common.Script.Script.ReloadMe();
    }

    private void BinderPG()
    {
        //初始化界面的播放地址
        PowerCreator.LMS.Course.Entity.VOTResource voResource = opCourse.LoadResource(int.Parse(ViewState["ResourceID"].ToString()));
        lbl_ResourceName.Text = voResource.ResourceName;
        lab_ClickNum.Text = voResource.ResourceClickNum.ToString();

        if (voResource.ResourceID < 0)
        {
            Script.ShowAndCloseMe(Page, config.GetLanagerValueByKey("theme_Comment_OpenCourseware_Msg1", PowerCreator.LMS.Language.LanagetItemType.Page));
            return;
        }

        int userNum = 0;
        DataTable dt = new DataTable();
        string sql = "select distinct FKGradeUserID from TGrade where FKGradeSkillID<>0 and FKGradeResourceID=" + voResource.ResourceID + "";
        PowerCreator.LMS.Web.Grade.GradeManager op = new PowerCreator.LMS.Web.Grade.GradeManager();
        userNum = objViewQuery.Count(sql);
        if (userNum > 0)
        {
            sql = "select sum(GradeScore) as sum from TGrade where FKGradeResourceID=" + voResource.ResourceID + "";
            dt = objViewQuery.Query(sql);
            if (dt.Rows.Count > 0)
            {
                lab_AvgScore.Text = Convert.ToString(int.Parse(dt.Rows[0][0].ToString()) / userNum);
            }

        }
        else
        {
            lab_AvgScore.Text = "0";
        }

        double result = Convert.ToDouble(lab_AvgScore.Text) / int.Parse(objViewQuery.Query(SEARCH_GETSUMSCORE).Rows[0][0].ToString());
        int countStart = Convert.ToInt32(result * 10);
        string str_Star = "";
        for (int i = 0; i < 10; i++)
        {

            if (i < countStart)
            {
                str_Star += IMG_OK;
            }
            else
            {
                str_Star += IMG_NO;
            }


        }
        lab_Star.Text = str_Star;
        //if (!CheckFile(voResource)) return;
        if (PowerCreator.LMS.Web.Config.WebConfig.IsUseLmsModel)
        {
            string url = PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + voResource.ResourceUrl + voResource.ResourceEntry;
            fileUrl = url;
            if (voResource.ResourceClass == Convert.ToInt16(SysResourceType.PowerCreator))
            {
                fileUrl = PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + voResource.ResourceUrl;
                //fileUrl = "../Single/content.aspx?fileUrl=" + fileUrl;
                fileUrl = string.Format("../Single/content.aspx?rsd={0}", ViewState["ResourceID"]);

            }
            else if (voResource.ResourceClass == Convert.ToInt16(SysResourceType.Video))
            {
                //string ServerIP;
                //if (PowerCreator.LMS.Web.Config.WebConfig.IsUseURLIP)
                //{
                //    int index = Request.Url.Authority.IndexOf(":", 0);
                //    if (index != -1)
                //    {
                //        ServerIP = Request.Url.Authority.Remove(index);
                //    }
                //    else
                //    {
                //        ServerIP = Request.Url.Authority;
                //    }

                //    fileUrl = "mms://" + ServerIP + voResource.ResourceUrl + voResource.ResourceEntry;
                //}
                //else
                //{
                //    PowerCreator.LMS.ViewQuery.ViewQuery opView = new PowerCreator.LMS.ViewQuery.ViewQuery();
                //    string sDirName = opResource.GetDirctoryName(voResource.ResourceUrl);
                //    string search = "select VirId,VirIisName,VirMmsName,VirIp from TVirtualDirectory where VirIisName='" + sDirName + " '";
                //    DataTable dtDir = opView.Query(search);
                //    if (dtDir.Rows.Count == 1)
                //    {
                //        ServerIP = dtDir.Rows[0]["VirIp"].ToString();
                //        string sResourceMMSUrl = voResource.ResourceUrl.Replace(sDirName, dt.Rows[0]["VirMmsName"].ToString());
                //        fileUrl = "mms://" + ServerIP + sResourceMMSUrl + voResource.ResourceEntry;
                //    }
                //}
                fileUrl = string.Format("../Video/OpenVideo.aspx?rsd={0}", ViewState["ResourceID"]);
            }

        }
        else
        {

            string url = PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + voResource.ResourceUrl + voResource.ResourceEntry;
            fileUrl = url;
            if (voResource.ResourceClass == Convert.ToInt16(SysResourceType.PowerCreator))
            {
            }
            else if (voResource.ResourceClass == Convert.ToInt16(SysResourceType.Video))
            {
                string ServerIP;
                if (PowerCreator.LMS.Web.Config.WebConfig.IsUseURLIP)
                {
                    int index = Request.Url.Authority.IndexOf(":", 0);
                    if (index != -1)
                    {
                        ServerIP = Request.Url.Authority.Remove(index);
                    }
                    else
                    {
                        ServerIP = Request.Url.Authority;
                    }

                    fileUrl = "mms://" + ServerIP + voResource.ResourceUrl + voResource.ResourceEntry;
                }
                else
                {
                    PowerCreator.LMS.ViewQuery.ViewQuery opView = new PowerCreator.LMS.ViewQuery.ViewQuery();
                    string sDirName = opResource.GetDirctoryName(voResource.ResourceUrl);
                    string search = "select VirId,VirIisName,VirMmsName,VirIp from TVirtualDirectory where VirIisName='" + sDirName + " '";
                    DataTable dtDir = opView.Query(search);
                    if (dtDir.Rows.Count == 1)
                    {
                        ServerIP = dtDir.Rows[0]["VirIp"].ToString();
                        string sResourceMMSUrl = voResource.ResourceUrl.Replace(sDirName, dt.Rows[0]["VirMmsName"].ToString());
                        fileUrl = "mms://" + ServerIP + sResourceMMSUrl + voResource.ResourceEntry;
                    }
                }
                fileUrl = "OpenVideo.aspx?fileUrl=" + fileUrl;

            }

        }

 

    }
    /// <summary>
    /// 检测文件是否存在
    /// </summary>
    /// <returns></returns>
    private bool CheckFile(PowerCreator.LMS.Course.Entity.VOTResource info)
    {
        string path = info.ResourceUrl + info.ResourceEntry;

        if (opResource.ExistsResourcePath(path))
        {
            //isUpdateCourse = "1";
            return true;
        }
        else
        {
            isUpdateCourse = "0";
            //是否创建一个界面，用来提交该处的课件信息?      skey 2009-7-20
            Script.ShowAndCloseMe(Page, config.GetLanagerValueByKey("theme_Comment_OpenCourseware_Msg2", PowerCreator.LMS.Language.LanagetItemType.Page));
            return false;
        }
    }

    private void SetOpenHistoryUrl()
    {
        url = PowerCreator.LMS.Common.Utils.WebUtils.WebRoot + string.Format(_openhistoryurl, ViewState["ProjectID"], ViewState["ClassID"], GetLoginEntity.UserID.ToString(), ViewState["ProjectResourceID"], ViewState["CoursResourceID"], ViewState["ResourceID"], DateTime.Now.ToString());
    }


    private void BinderCourseResource(string cid)
    {
        //string search = "select * from TResource where ResouceID in (select )";

        string search = "FKCourseresCourseID =" + cid + "and FKCoursersResourceID<>" + ViewState["ResourceID"].ToString();
        DataTable dt = opCourse.QueryCourseResource(search);
        List<CourseResourceInfo> list = new List<CourseResourceInfo>();
        //if (ViewState["ProjectID"].ToString() != "0")
        //{
        //    list = FillListResource(dt);
        //}
        //else
        //{
        list = FillList(dt);
        //}

        int count = list.Count;
        if (count > 10)
        {
            if (!PowerCreator.LMS.SCR.Dog.CheckDog())
            {
                list.RemoveRange(10, count - 10);

            }
        }


        rpt_OtherCourseResource.DataSource = list;
        rpt_OtherCourseResource.DataBind();

    }
    private void BinderOtherStowResource()
    {
        PowerCreator.LMS.ViewQuery.ViewQuery op = new PowerCreator.LMS.ViewQuery.ViewQuery();
        string search = "Select * from TResource where ResourceID in (Select FKResourceID from TUserStowResource where FKUserID =" + login.UserID + " and FKResourceID<>" + ViewState["ResourceID"].ToString()+")";
        DataTable dt = op.Query(search);
        List<CourseResourceInfo> list = new List<CourseResourceInfo>();
        int num = 6;
        if (dt.Rows.Count < 6)
            num = dt.Rows.Count;
        for (int i = 0; i < num; i++)
        {
            CourseResourceInfo item = new CourseResourceInfo();
            //此处为课件ID，暂时用此替代，不再修改类库，只有此文件如此使用
            item.ProjectResourceID = int.Parse(dt.Rows[i]["ResourceID"].ToString());
            item.CoursersResourceID = 0;
            item.ResourceName = dt.Rows[i]["ResourceName"].ToString();
            item.CoursersResourceUrl = GetPath(dt.Rows[i]["ResourceUrl"].ToString(), int.Parse(dt.Rows[i]["ResourceClass"].ToString()));
            item.CoursersResourceImageUrl = item.CoursersResourceUrl + GetPicName(dt.Rows[i]["ResourceEntry"].ToString(), int.Parse(dt.Rows[i]["ResourceClass"].ToString()));
            //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourse.aspx中如此使用）
            item.CoursersResourceEntry = " href=\"OpenCourseware.aspx?ResourceID=" + dt.Rows[i]["ResourceID"].ToString() + "&CourseResourceID=0&CourseID=0\" ";
            list.Add(item);
        }

        int count = list.Count;
        if (count > 10)
        {
            if (!PowerCreator.LMS.SCR.Dog.CheckDog())
            {
                list.RemoveRange(10, count - 10);

            }
        }

        rpt_OtherCourseResource.DataSource = list;
        rpt_OtherCourseResource.DataBind();

    }



    //DataTable为多表联链接查询后的数据
    private List<CourseResourceInfo> FillList(DataTable dt)
    {

        List<CourseResourceInfo> list = new List<CourseResourceInfo>();
        int num = 6;
        if (dt.Rows.Count < 6)
            num = dt.Rows.Count;
        for (int i = 0; i < num; i++)
        {
            if (dt.Rows[i]["FKCoursersResourceID"].ToString() != ViewState["ResourceID"].ToString())
            {
                CourseResourceInfo item = new CourseResourceInfo();
                item.CourseID = int.Parse(dt.Rows[i]["FKCourseresCourseID"].ToString());
                item.CourseresID = int.Parse(dt.Rows[i]["CourseresID"].ToString());
                item.CoursersRestpID = int.Parse(dt.Rows[i]["FKCoursersRestpID"].ToString());


                VOTResourceType voResourceType = opCourse.LoadResourceType(item.CoursersRestpID);
                VOTCourseResource vo = opCourse.LoadCourseResource(item.CourseresID);
                //item.CoursersRestpName = voResourceType.RestpName;
                item.CoursersClassID = int.Parse(dt.Rows[i]["CoursersClass"].ToString());
                //item.CoursersClassName = opCourse.GetCoursersClassByData(item.CoursersClassID, GetLanageValueByKey("Resource_Class1", PowerCreator.LMS.Language.LanagetItemType.Page), GetLanageValueByKey("Resource_Class2", PowerCreator.LMS.Language.LanagetItemType.Page));

                if (item.CoursersClassID == Convert.ToInt16(CoursersClass.Courseware))  //课件资源
                {
                    item.CoursersResourceID = int.Parse(dt.Rows[i]["FKCoursersResourceID"].ToString());
                    VOTResource voResource = opCourse.LoadResource(item.CoursersResourceID);

                    //实际为课件ID 此处用其代替，不再修改类库
                    item.ProjectResourceID = voResource.ResourceID;
                    item.ResourceName = voResource.ResourceName;
                    //item.CoursersResourceAuthor = voResource.ResourceAuthor;
                    //item.CoursersResourceDescription = voResource.ResourceDescription;
                    item.CoursersResourceUrl = GetPath(voResource.ResourceUrl, voResource.ResourceClass);
                    item.CoursersResourceImageUrl = item.CoursersResourceUrl + GetPicName(voResource.ResourceEntry, voResource.ResourceClass);
                    if (ViewState["ProjectID"].ToString() != "0")
                        //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                        item.CoursersResourceEntry = " href=\"OpenPowercreator.aspx?ProjectID=" + ViewState["ProjectID"].ToString() + "&ProjectClassID=" + ViewState["ClassID"].ToString() + "&ProjectResourceID=" + ViewState["ProjectResourceID"].ToString() + "&CourseResourceID=" + vo.CourseresID.ToString() + "&ResourceID=" + vo.FKCoursersResourceID.ToString() + "&CourseID=" + ViewState["CourseID"] + "\" ";
                    else
                        //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                        item.CoursersResourceEntry = " href=\"OpenCourseware.aspx?ResourceID=" + voResource.ResourceID.ToString() + "&CourseResourceID=" + vo.CourseresID.ToString() + "&CourseID=" + ViewState["CourseID"] + "\" ";


                }
                else if (item.CoursersClassID == Convert.ToInt16(CoursersClass.Paper)) //课程资源
                {
                    item.CoursersResourceID = int.Parse(dt.Rows[i]["FKCoursersPaperID"].ToString());
                    VOPaper voPaper = opPaper.LoadPaper(item.CoursersResourceID);
                    item.ResourceName = voPaper.PaperName;
                    //item.CoursersResourceDescription = voPaper.PaperName;
                    item.CoursersResourceUrl = "";
                    //实际为课件ID 此处用其代替，不再修改类库
                    item.ProjectResourceID = voPaper.PaperID;
                    item.CoursersResourceImageUrl = "images/Exam.jpg";

                    if (login != null)
                    {

                        NewProjectPlanInfo info = new NewProjectPlanInfo();
                        info.UserID = login.UserID;
                        info.ProjectID = int.Parse(ViewState["ProjectID"].ToString());
                        info.ClassID = int.Parse(ViewState["ClassID"].ToString());

                        if (ViewState["ProjectID"].ToString() != "0")
                        {
                            PowerCreator.LMS.Web.Paper.ManagerPaper objManagerPaper = new ManagerPaper();
                            ProjectResource opProjectResource = new ProjectResource();
                            VOTProjectResource voProjectResource = opProjectResource.LoadProjectResource(int.Parse(ViewState["ProjectResourceID"].ToString()));
                            NewProjectPlan opProjectPlan = new NewProjectPlan();

                            string bukao = "0"; //是否补考0：不是，1：是	
                            int exampapercount = opProjectPlan.QueryExamPaperCount(voProjectResource, info, item.CoursersResourceID);
                            if (exampapercount != 0)
                            {
                                bukao = "1";
                            }
                            if (exampapercount == 0)
                            {
                                //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                                item.CoursersResourceEntry = " href=\"" + WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=" + info.ProjectID + "&ProjectClassID=" + info.ClassID + "&IsBuKao=" + bukao + "&ProjectResourceID=" + ViewState["ProjectResourceID"].ToString() + "&CourseResourceID=" + item.CourseresID + "&CourseID=" + item.CourseID.ToString() + "\" ";
                            }
                            else
                            {
                                if (voProjectResource.ProresPaperMakeupNum <= exampapercount)
                                {
                                    item.CoursersResourceEntry = "";
                                    item.CoursersResourceMsg = GetLanageValueByKey("web_ProjectResource_msg_m2", PowerCreator.LMS.Language.LanagetItemType.Page);
                                }
                                else
                                {
                                    //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                                    item.CoursersResourceEntry = " href=\"" + WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=" + info.ProjectID + "&ProjectClassID=" + info.ClassID + "&IsBuKao=" + bukao + "&ProjectResourceID=" + ViewState["ProjectResourceID"].ToString() + "&CourseResourceID=" + item.CourseresID + "&CourseID=" + item.CourseID.ToString() + "\" ";
                                }
                            }
                        }
                        else
                        {
                            PowerCreator.LMS.Web.Paper.ManagerPaper objManagerPaper = new ManagerPaper();
                            string search = " FKUPHistoryUserID=" + login.UserID.ToString() + " and FKUPHistoryCourseID=" + item.CoursersResourceID.ToString() + " and FKUPHistoryPaperID=" + dt.Rows[i]["FKCoursersPaperID"].ToString();

                            DataTable dt_UserPaperHistory = objManagerPaper.QueryUserPaperHistory(search);
                            if (dt_UserPaperHistory.Rows.Count != 0)
                            {
                                string readState = dt_UserPaperHistory.Rows[0]["UPHistoryReadState"].ToString();
                                string SubmitTime = dt_UserPaperHistory.Rows[0]["UPHistorySubmitTime"].ToString().Trim();
                                if (readState == "1")
                                    //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                                    item.CoursersResourceEntry = " href=\"" + WebUtils.WebRoot + "/web/UserObject/ReadedPaper.aspx?PaperID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ClassID=0&CourseID=" + item.CourseID.ToString() + "&UserID=" + login.UserID.ToString() + "\" ";
                                else if (readState == "0" && SubmitTime == "")
                                    //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                                    item.CoursersResourceEntry = " href=\"" + WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ProjectClassID=0&IsBuKao=0&ProjectResourceID=0&CourseResourceID=0&CourseID=" + item.CourseID.ToString() + "\" ";
                                else
                                {
                                    item.CoursersResourceEntry = "#";
                                    item.CoursersResourceMsg = config.GetLanagerValueByKey("theme_Paper_ExamMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
                                }

                            }
                            else
                                //此处为打开课件的URL，为不在修改类库，此处用其代替，只在此文件与OpenCourseWareCommentNew.aspx中如此使用）
                                item.CoursersResourceEntry = " href=\"" + WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ProjectClassID=0&IsBuKao=0&ProjectResourceID=0&CourseResourceID=0&CourseID=" + item.CourseID.ToString() + "\" ";
                        }

                    }

                    else
                    {
                        item.CoursersResourceEntry = "#";
                        item.CoursersResourceMsg = config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page);

                    }
                }
                list.Add(item);
            }
        }
        return list;
    }



    protected void rpt_ResourceList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "download")
        {
            //打开看看
            if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
            {
                PowerCreator.LMS.Common.Script.Script.Alert(config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
                return;
            }
            if (e.CommandArgument.ToString() == "0")
            {

                Label lbl_ResourceID = (Label)e.Item.FindControl("lbl_ResourceID");

                VOTResource voResource = opCourse.LoadResource(int.Parse(lbl_ResourceID.Text));



                if (ViewState["ProjectID"].ToString() == "0")
                {
                    Script.RedirectURL("OpenCourseware.aspx?ResourceID=" + voResource.ResourceID.ToString() + "&CourseResourceID=0&CourseID=" + ViewState["CourseID"]);
                }
                else
                {
                    string url = "OpenPowercreator.aspx?ProjectID=" + ViewState["ProjectID"].ToString() + "&ProjectClassID=" + ViewState["ClassID"].ToString() + "&ProjectResourceID=" + ViewState["ProjectResourceID"].ToString() + "&CourseResourceID=0&ResourceID=" + voResource.ResourceID.ToString() + "&CourseID=" + ViewState["CourseID"];
                    Script.RedirectURL(url);
                }

            }
            else
            {
                VOTCourseResource vo = opCourse.LoadCourseResource(int.Parse(e.CommandArgument.ToString()));
                Label lbl_msg = (Label)e.Item.FindControl("lbl_resourcetype_paper");
                if (vo != null)
                {

                    VOTResource voResource = opCourse.LoadResource(vo.FKCoursersResourceID);
                    if (voResource == null)
                    {
                        lbl_msg.Text = config.GetLanagerValueByKey("ResourceList_msg_m2", PowerCreator.LMS.Language.LanagetItemType.Page);
                        return;
                    }
                    if (ConfigurationManager.AppSettings["PubliceIsLogin"].ToString() == "1")
                    {
                        if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
                        {
                            Script.Alert(config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
                            return;

                        }
                    }
                    if (vo.CoursersClass == 1)
                    {
                        //Script.NewOpenURL(WebUtils.WebRoot + voResource.ResourceUrl + voResource.ResourceEntry, "testfileurl");
                        string _fileUrl = WebUtils.WebRoot + voResource.ResourceUrl + voResource.ResourceEntry;
                        //string path = Server.MapPath(_fileUrl);

                        if (voResource.ResourceClass != 3)
                        {

                            if (!voResource.ResourceMmsUpdateState)//检查课件是否是第一次被点播，如果是第一次被点播，则修改remoteclip.asx文件以及读取content.xml文件，修改Tgrade表中的相关字段（针对直播后载入新课件以期后期评论）。
                            {
                                if (vo.CourseresID > 0)
                                {
                                    VOTOCourse voCourse = opCourse.LoadVOTCourse(vo.FKCourseresCourseID);
                                    if (voCourse.Course_Id > 0)
                                    {
                                        opResource.UpdataResourceByEditMMS(voResource);
                                    }
                                }

                            }

                            //if (PowerCreator.LMS.Web.Config.WebConfig.IsUseWeGe)
                            //{
                            //    if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
                            //    {
                            //        Script.Alert(config.GetLanagerValueByKey("theme_Channel_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
                            //        return;
                            //    }

                            //}
                        }

                        voResource.ResourceClickNum += 1;
                        voResource.ResourceLastVisitTime = DateTime.Now;
                        if (!opCourse.UpdateResource(voResource))
                        {
                            //lab_err.Text = config.GetLanagerValueByKey("theme_PageCode_ErrmMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
                        }
                        if (ViewState["ProjectID"].ToString() == "0")
                        {
                            Script.RedirectURL("OpenCourseware.aspx?ResourceID=" + voResource.ResourceID.ToString() + "&CourseResourceID=" + vo.CourseresID.ToString() + "&CourseID=" + ViewState["CourseID"]);
                        }
                        else
                        {
                            string url = "OpenPowercreator.aspx?ProjectID=" + ViewState["ProjectID"].ToString() + "&ProjectClassID=" + ViewState["ClassID"].ToString() + "&ProjectResourceID=" + ViewState["ProjectResourceID"].ToString() + "&CourseResourceID=" + vo.CourseresID.ToString() + "&ResourceID=" + vo.FKCoursersResourceID.ToString() + "&CourseID=" + ViewState["CourseID"];
                            Script.RedirectURL(url);
                        }


                    }
                    else
                    {

                        //PowerCreator.LMS.Web.User.LoginEntity login = (PowerCreator.LMS.Web.User.LoginEntity)Session[WebConfig.SESSION_USER_USERINFO];
                        if (login == null)
                        {
                            Script.Alert(config.GetLanagerValueByKey("theme_Course_LoginMsg", PowerCreator.LMS.Language.LanagetItemType.Page));
                            return;
                        }


                        PowerCreator.LMS.Web.Paper.ManagerPaper objManagerPaper = new ManagerPaper();
                        string search = " FKUPHistoryUserID=" + login.UserID.ToString() + " and FKUPHistoryCourseID=" + vo.FKCourseresCourseID.ToString() + " and FKUPHistoryPaperID=" + vo.FKCoursersPaperID.ToString();

                        DataTable dt_UserPaperHistory = objManagerPaper.QueryUserPaperHistory(search);
                        if (dt_UserPaperHistory.Rows.Count != 0)
                        {
                            string readState = dt_UserPaperHistory.Rows[0]["UPHistoryReadState"].ToString();
                            string SubmitTime = dt_UserPaperHistory.Rows[0]["UPHistorySubmitTime"].ToString().Trim();
                            if (readState == "1")
                            {
                                Script.RedirectURL(WebUtils.WebRoot + "/web/UserObject/ReadedPaper.aspx?PaperID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ClassID=0&CourseID=" + vo.FKCourseresCourseID.ToString() + "&UserID=" + login.UserID.ToString());
                            }
                            else if (readState == "0" && SubmitTime == "")
                            {
                                Script.RedirectURL(WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ProjectClassID=0&IsBuKao=0&ProjectResourceID=0&CourseResourceID=0&CourseID=" + vo.FKCourseresCourseID.ToString());
                            }
                            else
                            {
                                lbl_msg.Text = config.GetLanagerValueByKey("theme_Paper_ExamMsg", PowerCreator.LMS.Language.LanagetItemType.Page);

                            }

                        }
                        else
                        {
                            Script.NewOpenURL(WebUtils.WebRoot + "/web/UserObject/OpenPaperList.aspx?ResourceID=" + vo.FKCoursersPaperID.ToString() + "&ProjectID=0&ProjectClassID=0&IsBuKao=0&ProjectResourceID=0&CourseResourceID=0&CourseID=" + vo.FKCourseresCourseID.ToString());
                        }



                    }




                }
                else
                {
                    lbl_msg.Text = config.GetLanagerValueByKey("ResourceList_msg_m3", PowerCreator.LMS.Language.LanagetItemType.Page);
                }
            }
        }
    }


    private string GetPicName(string fileName, int Resourceclass)
    {
        string rt = "images/Exam.jpg";
        if (Resourceclass == 1)
        {
            rt = "000.jpg";
        }
        else if (Resourceclass == 2)
        {
            string[] fileNames = fileName.Split('.');
            if (fileNames.Length == 2)
                rt = fileNames[0].ToString() + ".jpg";
        }
        return rt;
    }
    private string GetPath(string Path, int Resourceclass)
    {
        string rt = Path;
        if (Resourceclass != 1 && Resourceclass != 2)
        {
            rt = "";
        }
        return rt;
    }
}
